{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "98d4f33d",
   "metadata": {},
   "source": [
    "# README\n",
    "\n",
    "这是一个用Python编写的医学图像处理程序 **M**edical **I**mage **E**nhancement **T**ool **B**ox(MIETB) ，可以用于各种医学图像处理相关的任务。\n",
    "\n",
    "## 效果说明\n",
    "\n",
    "该程序可以实现以下功能：\n",
    "\n",
    "- 图像超分辨率重建\n",
    "    - scale 输入一个放大倍数，支持[2,4]倍\n",
    "    - 其他高倍数的算法定制，可以联系张老师，微信：OnekeyAI4U\n",
    "\n",
    "## 获取待提取特征的文件\n",
    "\n",
    "提供两种批量处理的模式：\n",
    "1. 目录模式，提取指定目录下的所有.nii.gz文件的特征。默认寻找目录下所有的nii.gz数据\n",
    "2. 文件模式，待提取的数据存储在文件中，每行一个样本。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "df6f2a55",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'\n",
    "from onekey_algo import OnekeyDS as okds\n",
    "from onekey_algo import get_param_in_cwd\n",
    "\n",
    "# 目录模式\n",
    "scale = get_param_in_cwd('scale', 4)\n",
    "mydir = get_param_in_cwd('rad_dir', os.path.join(okds.ct, 'images'))\n",
    "samples = []\n",
    "for r, ds, fs in os.walk(mydir):\n",
    "    samples.extend([os.path.join(r, p) for p in fs if p.endswith('.nii.gz')])\n",
    "\n",
    "# 文件模式\n",
    "# test_file = ''\n",
    "# with open(test_file) as f:\n",
    "#     test_samples = [l.strip() for l in f.readlines()]\n",
    "\n",
    "# 自定义模式\n",
    "# test_sampleses = ['path2nii.gz']\n",
    "samples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "577fbf57",
   "metadata": {},
   "outputs": [],
   "source": [
    "from onekey_algo.mietb.super_resolution.eval_super_res_reconstruction import init as init_super\n",
    "from onekey_algo.mietb.super_resolution.eval_super_res_reconstruction import inference as inference_super\n",
    "\n",
    "save_dir = get_param_in_cwd('save_dir', None)\n",
    "print(save_dir)\n",
    "model, device = init_super(scale)\n",
    "inference_super(samples, model, device, scale, save_dir=save_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2157e73d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
